<?php
	include 'init.php';
	if ($listid)
	{
            $listid	= $_POST[listid];
            $cellphone	= $_POST[cellphone];
            $message	= $_POST[message];
            $message    = utf8_decode($message);

            $con = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
            mysql_select_db("$DBName", $con);

            // The neccesary variables are set.
            $url = "http://www.cpsms.dk/sms/";
            $url .= "?message=" . urlencode("$message");
            $url .= "&recipient=$cellphone"; // Recipient
            $url .= "&username=kvist"; // Username
            $url .= "&password=vi4veddet"; // Password
            $url .= "&from=" . urlencode("$fromphone"); // Sendername

            // The url is opened
            $reply  = file_get_contents($url);
            //$reply .= " - $shortname";

            $sql="INSERT INTO $TSendSMS (ListId, CellPhone, Message, status)
                    VALUES ('$listid','$cellphone','$message','$reply')";

            if (!mysql_query($sql,$con))
            {
                die('Error: ' . mysql_error());
            }

            mysql_close($con);

            $to = "/receivers/$listid/$fromphone";
            header('Location: '. $to);
	}
?>